<?php
namespace app\common\library\xilujob\resume;


use app\common\library\xilujob\ResumeLibrary;
use app\common\model\xilujob\Resume;
use app\common\model\xilujob\ResumeSkill;
use app\common\model\xilujob\SkillLevel;
use think\Model;

class Skill extends BaseModule {

    protected $name = ResumeLibrary::MODULE_SKILL;

    public function onCreateResume(Resume $resume) {}

    /**
     * 获取所有字段的key
     * @return array
     */
    protected function keys() {
        return ['skill_name','level_id'];
    }

    /**
     * 获取验证规则
     * @return array
     */
    protected function getRules() {
        return [
            'skill_name' => 'require|length:1,20',
            'level_id' => function($value,$data) {
                $value = intval($value);
                if(!$value) {
                    return false;
                }
                return SkillLevel::where('id', $value)->count()>0;
            }
        ];
    }

    /**
     * 获得Model实例
     * @return Model
     */
    protected function getModel() {
        return New ResumeSkill();
    }

    /**
     * @return array score: 当前分数， max: 满分
     */
    public function getCompleteScore() {
        $max = 10;
        $count = ResumeSkill::where('resume_id',$this->resume->id)->count();
        $score = $count>0 ? 10 : 0;
        return ['score'=>$score, 'max'=>$max];
    }

}